﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using AspNetCs.Bll;
using AspNetCs.Common;
using AspNetCs.Enumerations;
using AspNetCs.Model;

public partial class Master_ConsumptionRecord : Admin_BasePage
{

    protected string QueryUser = "";
    protected string QueryUserType = "";

    protected string WhereStr = " where  id<>0 ";
    protected void Page_Load(object sender, EventArgs e)
    {

        IsExit();
        if ((Request["Un"] != null) && (Request["Ut"] != null))
        {
            QueryUser = StringHelper.HtmlEncrypt(StringHelper.RemoveHtml(Request["Un"]));
            QueryUserType = StringHelper.isNumber_int(Request["Ut"].ToString()).ToString();
        }
        if (QueryUser != "" && QueryUserType != "")
        {


            WhereStr += " and  UserId=" + QueryUser + " and UserType= " + QueryUserType;

        }

        if (!IsPostBack)
        {
            dataBind();
        }
    }

    public string GetUserTypeName(string userType)
    {
        UserTypeEnum userTypeEnum = (UserTypeEnum)StringHelper.isNumber_int(userType);
        return EnumDescription.GetFieldText(userTypeEnum);
    }

    protected void dataBind()
    {
        string cmdText = "select * from point_log as po " + WhereStr + " order by Id desc";
        AspNetCs.Common.DataPagesOperate operate = new DataPagesOperate();

        operate.BindRepeater(cmdText, AspNetPager1, "Id desc", "Id", rptNetMuList);


    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        dataBind();
    }
    protected void rptNetMuList_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        Label lblName = e.Item.FindControl("lblName") as Label;
        HiddenField hldUserId = e.Item.FindControl("hldUserId") as HiddenField;
        HiddenField hldUserType = e.Item.FindControl("hldUserType") as HiddenField;
        if (lblName != null && hldUserId != null && hldUserType != null)
        {
            if ((int)UserTypeEnum.User == StringHelper.isNumber_int(hldUserType.Value))
            {
                if (hldUserId.Value == "0")
                {
                    lblName.Text ="<a href='ConsumptionRecord.aspx?Ut=" + (int)UserTypeEnum.User + "&Un=" + hldUserId.Value + "'>所有会员</a>";
                }
                else
                {
                    string cmdText = "select UserName from users where userid={0}";
                    cmdText = string.Format(cmdText, hldUserId.Value);
                    DataTable dataTable = new DataTable();
                    dataTable = ExcuteSqlTextBLL.GetDataTable(cmdText);

                    if (dataTable.Rows.Count > 0)
                    {

                        lblName.Text = "<a href='ConsumptionRecord.aspx?Ut=" + (int)UserTypeEnum.User + "&Un=" + hldUserId.Value + "'>" + dataTable.Rows[0][0].ToString() + "</a>";
                    }
                }

            }
            else if ((int)UserTypeEnum.Agent == StringHelper.isNumber_int(hldUserType.Value))
            {
                if (hldUserId.Value == "0")
                {
                    lblName.Text = "<a href='ConsumptionRecord.aspx?Ut=" + (int)UserTypeEnum.Agent + "&Un=" + hldUserId.Value + "'>所有代理商</a>";
                }
                else
                {
                    string cmdText = "select AgentUserName from Agent where id={0}";
                    cmdText = string.Format(cmdText, hldUserId.Value);
                    DataTable dataTable = new DataTable();
                    dataTable = ExcuteSqlTextBLL.GetDataTable(cmdText);
                    if (dataTable.Rows.Count > 0)
                    {

                        lblName.Text = "<a href='ConsumptionRecord.aspx?Ut=" + (int)UserTypeEnum.Agent + "&Un=" + hldUserId.Value + "'>" + dataTable.Rows[0][0].ToString() + "</a>";

                    }
                }
            }
        }
    }
}
